<?php

class FHVASModulesForm extends Zend_Form
{
    private $picture_path = "";
    private $logo_path = "";
	private $funeral_home = null;
	
    public function __construct($options=array())
    {
        parent::__construct($options);

		$VAS_fh_id = $options['VAS_fh_id'];
		$VAS_modules = $options['VAS_modules'];
		
        // set form name and POST
        $this->setName('fh_modules');
        $this->setMethod('post');

        $decorators = array(
            'ViewHelper',
//            array(array('labelBr'=>'HtmlTag'), array('tag'=>'br')),
            array('Label', array('placement'=>'prepend')),
            array( array('outerDiv'=>'HtmlTag'), array('tag'=>'div', 'style'=>'margin-top:5px')),
        );
		
		$style = 'font-size:14pt';
		
		$f_id = new Zend_Form_Element_Hidden('VAS_fh_id');
		$f_id->setValue($VAS_fh_id);

		$f_id->setDecorators($decorators);
		
		$f_name = new Zend_Form_Element_Text('name', array('label'=>'Name:', 'size'=>'30', 'style'=>$style));
		$f_name->setDecorators($decorators);
		$f_address = new Zend_Form_Element_Text('addr1', array('label'=>'Address:', 'size'=>'30', 'style'=>$style));
		$f_address->setDecorators($decorators);
		$f_city = new Zend_Form_Element_Text('city', array('label'=>'City:', 'size'=>'30', 'style'=>$style));
		$f_city->setDecorators($decorators);
		$f_state = new Zend_Form_Element_Text('state', array('label'=>'State:', 'size'=>'2', 'style'=>$style));
		$f_state->setDecorators($decorators);
		$f_zip = new Zend_Form_Element_Text('zip', array('label'=>'Zip:', 'size'=>'10', 'style'=>$style));
		$f_zip->setDecorators($decorators);
		$f_phone = new Zend_Form_Element_Text('phone', array('label'=>'Phone:', 'size'=>'16', 'style'=>$style));
		$f_phone->setDecorators($decorators);
        // funeral home picture uploader
		
        $funeral_home_picture = new Zend_Form_Element_File('photo_image');
        $funeral_home_picture->setLabel('Upload a picture image:')
			->setRequired(true)
					->setDestination(ROOT_DIR.'/upload')
	        ->addValidator('Count', 1)     // ensure only 1 file
	        ->addValidator('Size', false, 502400) // limit to 500K
	        ->addValidator('Extension', false, 'jpg,png,gif'); // only JPEG, PNG, and GIFs

        $funeral_home_logo = new Zend_Form_Element_File('logo_image');
        $funeral_home_logo->setLabel('Upload a logo image:')
			->setRequired(false)
	        //->setDestination('/var/www/keystone/Zend-Project/upload')
					->setDestination(ROOT_DIR.'/upload')
	        ->addValidator('Count', 1)     // ensure only 1 file
	        ->addValidator('Size', false, 502400) // limit to 100K
	        ->addValidator('Extension', false, 'jpg,png,gif'); // only JPEG, PNG, and GIFs
   		
        // form's submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Submit');

        $this->addElements(
            array(
				$f_id, $f_name, $f_address, $f_city, $f_state, $f_zip, $f_phone,
				$funeral_home_picture, $funeral_home_logo
            )
        );
		
		$this->addElements(array($submit));
		
    }
    
    // dirt-simple template engine.
    public function render_with_template( $template_name )
    {
        $template_file_path = APP_DIR."/views/templates/$template_name";
        $template_contents = file_get_contents( $template_file_path );

        // str_replace() keywords, adding errors where needed
        $form_elements = $this->getElements();

		$template_contents = str_replace( "{FORM_ACTION}", $this->getAction(), $template_contents );
		$template_contents = str_replace( "{FORM_ENCODING}", $this->getEnctype(), $template_contents );
		
        $template_contents = str_replace( "{FUNERAL_HOME_ID}", $form_elements['VAS_fh_id'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_NAME}", $form_elements['name'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_ADDR1}", $form_elements['addr1'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_CITY}", $form_elements['city'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_STATE}", $form_elements['state'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_ZIP}", $form_elements['zip'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_PHONE}", $form_elements['phone'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_FAX}", $form_elements['fax'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_PRIMARY_EMAIL}", $form_elements['primary_email'], $template_contents );
 
        $template_contents = str_replace( "{FUNERAL_HOME_PIC_PATH}", $this->picture_path, $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_LOGO_PATH}", $this->logo_path, $template_contents ); 
		
		$template_contents = str_replace( "{FUNERAL_HOME_PIC_FILE}", $form_elements['photo_image'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_HOME_LOGO_FILE}", $form_elements['logo_image'], $template_contents );
		
        $template_contents = str_replace( "{SUBMIT_BUTTON}", $this->submit, $template_contents );

        echo $template_contents;
    }
}

?>
